package com.leoman.dao;

import com.leoman.entity.UserAddress;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * UserAddressDao
 * Created by 涂奕恒 on 2016/11/23 0023 下午 3:46.
 */
public interface UserAddressDao extends JpaRepository<UserAddress, Integer>, JpaSpecificationExecutor<UserAddress> {

    @Query("select a from UserAddress a where a.user.id = ?1")
    Page<UserAddress> iPageByUserId(Integer userId, Pageable pageable);

    @Query("select a from UserAddress a where a.user.id = ?1 and a.isDefault = 1")
    UserAddress findOneWithUserIdAndDefault(Integer userId);

    @Query("select a from UserAddress a where a.user.id = ?1")
    List<UserAddress> findListByUserId(Integer userId);
}